//
//  TTWelcomeViewController.swift
//  NewWeiBo
//
//  Created by 吴天益 on 2017/7/25.
//  Copyright © 2017年 ttt. All rights reserved.
//

import UIKit
import SnapKit
import YYWebImage

class TTWelcomeViewController: UIViewController {
    
    private lazy var backgroundImgV = UIImageView(image: UIImage(named: "ad_background"))
    
    private lazy var iconPlaceImgV: UIImageView = {
    
        let imageView = UIImageView()
        
//        print(TTUserAccountViewModel.shareViewModel.userAccountModel?.avatar_large)
        
        let url: URL? = URL(string: (TTUserAccountViewModel.shareViewModel.userAccountModel?.avatar_large)!)
        
        imageView.yy_setImage(with: url, placeholder: UIImage(named: "avatar_default_big"))
        
        return imageView
    }()
    
    private lazy var discribe: UILabel = {
        
        let lable = UILabel()
        lable.textAlignment = .center
        lable.font = UIFont.systemFont(ofSize: 14)
        lable.text = TTUserAccountViewModel.shareViewModel.userAccountModel?.name
        lable.alpha = 0
        return lable
    }()

    
    //自定义试图
    override func loadView() {
        view = backgroundImgV
    }
    
    

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(iconPlaceImgV)
        view.addSubview(discribe)
        
        //约束
        iconPlaceImgV.snp.makeConstraints { (make) in
            make.top.equalTo(view).offset(200)
            make.centerX.equalTo(view)
            make.width.height.equalTo(50)
        }
        discribe.snp.makeConstraints { (make) in
            make.top.equalTo(iconPlaceImgV.snp.bottom).offset(10)
            make.centerX.equalTo(view)
        }
        
        
        
    }
    
    //MARK: - 动画要放在这个方法,不然会有bug
    override func viewDidAppear(_ animated: Bool) {
        
        setupAnimation()
    }


    //MARK: - 动画制作
    func setupAnimation(){
        
        iconPlaceImgV.snp.updateConstraints { (make) in
            make.top.equalTo(view).offset(100)
        }
        
        UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10, options: [], animations: {
            
            self.view.layoutIfNeeded()
        }) { (_) in
            
            UIView.animate(withDuration: 1, animations: { 
                
                self.discribe.alpha = 1
            }, completion: { (_) in
                
                //发出通知,切换控制器
                NotificationCenter.default.post(name: NSNotification.Name(rawValue: switchWindowRootController), object: nil) 
            })
        }
        
        
        
    }



}
